package com.jyy.prefabricated.service.impl;

import com.jyy.prefabricated.entity.PublicTransfer;
import com.jyy.prefabricated.enums.DeletedEnum;
import com.jyy.prefabricated.mapper.PublicTransferMapper;
import com.jyy.prefabricated.service.PublicTransferService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 对公转账商户信息表(PublicTransfer)表服务实现类
 *
 * @author makejava
 * @since 2021-08-16 14:52:18
 */
@Service("publicTransferService")
public class PublicTransferServiceImpl implements PublicTransferService {
    @Resource
    private PublicTransferMapper publicTransferMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PublicTransfer queryById(Integer id) {
        return this.publicTransferMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<PublicTransfer> queryAllByLimit(int offset, int limit) {
        return this.publicTransferMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param publicTransfer 实例对象
     * @return 实例对象
     */
    @Override
    public PublicTransfer insert(PublicTransfer publicTransfer) {
        publicTransfer.setFlag(DeletedEnum.INVALID.getValue());
        this.publicTransferMapper.insert(publicTransfer);
        return publicTransfer;
    }

    /**
     * 修改数据
     *
     * @param publicTransfer 实例对象
     * @return 实例对象
     */
    @Override
    public PublicTransfer update(PublicTransfer publicTransfer) {
        this.publicTransferMapper.update(publicTransfer);
        return this.queryById(publicTransfer.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.publicTransferMapper.deleteById(id) > 0;
    }

    public  List<PublicTransfer> queryAll(PublicTransfer publicTransfer){
        return publicTransferMapper.queryAll(publicTransfer);
    }
}
